﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataContext;

namespace WorkFlowBLL
{
    public class CtrProduct
    {
        public List<uspProductGetByCateResult> ProductGetByCate(string kw, int cateID, int isQuantification, int isExistStock, int status)
        {
            return DAL.ProductInstance.CreateInstance().uspProductGetByCate(kw, cateID, isQuantification, isExistStock, status).ToList();
        }
        public List<uspProductGetByCateResult> ProductGetByCate(int cateID, int status, int isQuantification)
        {
            return DAL.ProductInstance.CreateInstance().uspProductGetByCate("", cateID, isQuantification, -1, status).ToList();
        }
        public List<uspProductGetQuantificationResult> ProductGetQuantification(int productID)
        {
            return DAL.ProductInstance.CreateInstance().uspProductGetQuantification(productID).ToList();
        }
        public uspQuantificationGetInfoByQuantificationIDResult QuantificationGetInfo(int quantifiID)
        {
            return DAL.ProductInstance.CreateInstance().uspQuantificationGetInfoByQuantificationID(quantifiID).FirstOrDefault();
        }
        public int QuantificationSetQuantity(int quantifiID, double quantity)
        {
            return DAL.ProductInstance.CreateInstance().uspQuantificationUpdateQuantity(quantifiID, quantity);
        }
        public int QuantificationDelete(int quantifiID)
        {
            return DAL.ProductInstance.CreateInstance().uspQuantificationDeleteByQuantificationID(quantifiID);
        }
        public uspProductGetInfoByProductIDResult ProductGetInfo(int proID)
        {
            return DAL.ProductInstance.CreateInstance().uspProductGetInfoByProductID(proID).FirstOrDefault();
        }
        public int QuantificationInsert(int productParentID, int productChildID, double quantifiID, string unit, string description)
        {
            return DAL.ProductInstance.CreateInstance().uspQuantificationInsert(productParentID, productChildID, quantifiID, unit, DateTime.Now, description);
        }

        public int ProductInsert(string productName, int unitID, string unit, int price, int priceIn, int categoryID, string description, bool isQuantification, bool isHasStock, int status)
        {
            return DAL.ProductInstance.CreateInstance().uspProductInsert(productName, unitID, unit, price, priceIn, categoryID, description, isQuantification, isHasStock, status);
        }

        public int ProductUpdate(int productID, string productName, int unitID, string unit, int price, int priceIn, int categoryID, string description, bool isQuantification, bool isHasStock, int status)
        {
            return DAL.ProductInstance.CreateInstance().uspProductUpdateByProductID(productID, productName, unitID, unit, price, priceIn, categoryID, description, isQuantification, isHasStock, status);
        }

        public int ProductDelete(int productID)
        {
            return DAL.ProductInstance.CreateInstance().uspProductDeleteByProductID(productID);
        }

        public int ProductUpdateQuantity(int productID, double quantity)
        {
            return DAL.ProductInstance.CreateInstance().uspProductQuantityUpdate(productID, quantity);
        }

        #region Bill
        /// <summary>
        /// Lấy danh sách hóa đơn bán hàng
        /// </summary>
        /// <param name="fromDate"></param>
        /// <param name="toDate"></param>
        /// <param name="adminID"></param>
        /// <returns></returns>
        public List<uspBillGetReportResult> GetBillReport(DateTime fromDate, DateTime toDate, int adminID, ref long? sumMoneyAll, ref long? priceServicesAll, ref long? promotionMoneyAll, ref long? totalMoneyAll)
        {
            return DAL.ProductInstance.CreateInstance().uspBillGetReport(fromDate, toDate, adminID, ref sumMoneyAll, ref priceServicesAll, ref promotionMoneyAll, ref totalMoneyAll).ToList();
        }
        /// <summary>
        /// Chi tiết hóa đơn
        /// </summary>
        /// <param name="billID"></param>
        /// <returns></returns>
        public List<uspBillDetailGetByBillIDResult> BillDetailsGetByBillID(int billID)
        {
            return DAL.ProductInstance.CreateInstance().uspBillDetailGetByBillID(billID).ToList();
        }
        /// <summary>
        /// Xóa mặt hàng trong hóa đơn
        /// </summary>
        /// <param name="billDetailID"></param>
        /// <returns></returns>
        public int BillDetailsDelete(int billDetailID)
        {
            return DAL.ProductInstance.CreateInstance().uspBillDetailDelete(billDetailID);
        }
        /// <summary>
        /// Thêm mới mặt hàng vào hóa đơn
        /// </summary>
        /// <param name="billID"></param>
        /// <param name="productID"></param>
        /// <param name="quantity"></param>
        /// <returns></returns>
        public int BillDetailsInsert(int billID, int productID, double quantity)
        {
            return DAL.ProductInstance.CreateInstance().uspBillDetailInsert(billID, productID, quantity, "");
        }
        /// <summary>
        /// Cập nhật số lượng mặt hàng trong hóa đơn
        /// </summary>
        /// <param name="billDetialID"></param>
        /// <param name="quantity"></param>
        /// <returns></returns>
        public int BillDetailsUpdateQuantity(int billDetialID, double quantity)
        {
            return DAL.ProductInstance.CreateInstance().uspBillDetailUpdateQuantity(billDetialID, quantity); ;
        }
        /// <summary>
        /// Cập nhật giá bán mới của mặt hàng trong hóa đơn
        /// </summary>
        /// <param name="billDetialID"></param>
        /// <param name="price"></param>
        /// <returns></returns>
        public int BillDetailsUpdatePrice(int billDetialID, int price)
        {
            return DAL.ProductInstance.CreateInstance().uspBillDetailUpdatePrice(billDetialID, price); ;
        }
        /// <summary>
        /// Cập nhật mô tả chi tiết hóa đơn
        /// </summary>
        /// <param name="billDetialID"></param>
        /// <param name="description"></param>
        /// <returns></returns>
        public int BillDetailsUpdateDescription(int billDetialID, string description)
        {
            return DAL.ProductInstance.CreateInstance().uspBillDetailUpdateDescription(billDetialID, description); ;
        }
        /// <summary>
        /// Lấy thông tin cơ bản hóa đơn
        /// </summary>
        /// <param name="billID"></param>
        /// <returns></returns>
        public uspBillGetInfoCommonResult BillGetInfoCommon(int billID)
        {
            return DAL.ProductInstance.CreateInstance().uspBillGetInfoCommon(billID).FirstOrDefault();
        }
        /// <summary>
        /// Thêm mới hóa đơn
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="tableID"></param>
        /// <returns></returns>
        public int BillInsert(int userID, int tableID)
        {
            return DAL.ProductInstance.CreateInstance().uspBillInsert(userID, tableID);
        }
        /// <summary>
        /// Đóng hóa đơn
        /// </summary>
        /// <param name="billID"></param>
        /// <returns></returns>
        public int BillClose(int billID)
        {
            return DAL.ProductInstance.CreateInstance().uspBillClose(billID);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="billIDFrom"></param>
        /// <param name="billIDTo"></param>
        /// <returns>-2: hóa đơn hiện tại ko tồn tại; -3: Hóa đơn đến ko tồn tại</returns>
        public int BillGross(int billIDFrom, int billIDTo)
        {
            return DAL.ProductInstance.CreateInstance().uspBillGross(billIDFrom, billIDTo);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="billID"></param>
        /// <param name="tableIDTo"></param>
        /// <returns>-2: Hóa đơn hiện tại ko tồn tại; -3: Bàn chuyển đến đã có người ngồi</returns>
        public int BillMove(int billID, int tableIDTo)
        {
            return DAL.ProductInstance.CreateInstance().uspBillMove(billID, tableIDTo);
        }
        /// <summary>
        /// Lấy giá dịch vụ, giảm giá, tổng tiền của hóa đơn
        /// </summary>
        /// <param name="billID"></param>
        /// <returns></returns>
        public uspBillGetPriceServiceAndPromotionResult BillGetPriceOther(int billID)
        {
            return DAL.ProductInstance.CreateInstance().uspBillGetPriceServiceAndPromotion(billID).FirstOrDefault();
        }
        /// <summary>
        /// Xóa đơn hàng
        /// </summary>
        /// <param name="billID"></param>
        /// <param name="acceptDeleteBillDetails"></param>
        /// <returns></returns>
        public int BillDelete(int billID, bool acceptDeleteBillDetails)
        {
            return DAL.ProductInstance.CreateInstance().uspBillDelete(billID, acceptDeleteBillDetails);
        }
        /// <summary>
        /// Cập nhật giá dịch vụ
        /// </summary>
        /// <param name="billID"></param>
        /// <param name="priceSer"></param>
        /// <returns></returns>
        public int BillUpdatePriceServices(int billID, int priceSer)
        {
            return DAL.ProductInstance.CreateInstance().uspBillUpdatePriceService(billID, priceSer);
        }
        /// <summary>
        /// Cập nhật tiền khuyến mãi
        /// </summary>
        /// <param name="billID"></param>
        /// <param name="promotionMoney"></param>
        /// <returns></returns>
        public int BillUpdatePromotionMoney(int billID, int promotionMoney)
        {
            return DAL.ProductInstance.CreateInstance().uspBillUpdatePromotionMoney(billID, promotionMoney);
        }
        #endregion
    }
}

